﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ThietBiSo.LinQDB;
using ThietBiSo.Models;
using ThietBiSo.UrlReview;

namespace ThietBiSo.Controllers
{
    public class dichvuController : ApplicationController
    {
        //
        // GET: /dichvu/

        MDichVu mdv = new MDichVu();
        DichVu dv = new DichVu();
        SEOUrl seo = new SEOUrl();
        //MNoiDungDichVuChung mnddvc = new MNoiDungDichVuChung();
        //NoiDungDichVuChung nd = new NoiDungDichVuChung();

        public ActionResult dichvu(int? id)
        {
            //var v = mnddvc.FindAll();
            //ViewData["noidungchungs"] = v;

            int pageString = id ?? 0;
            int page = pageString == 0 ? 1 : pageString;
            int total = mdv.GetTotal_DichVu();
            PagingController("/dichvu/dichvu/", total, page, "");
            ViewData["dichvus"] = mdv.GetList(start, offset);
            return View();
        }
        
        //public ActionResult Index1(string id)
        //{

        //    ViewData["title"] = mdv.GetTitleByMa(int.Parse(seo.CatChuoi(id)));
        //    ViewData["noidungs"] = mdv.GetNoiDung(int.Parse(seo.CatChuoi(id)));

        //    return View();
           
        //}

     

        

        //[HttpPost]
        //public ActionResult dichvu(FormCollection collection)
        //{
        //    try
        //    {

        //        //nd.ID = 1;
        //        //nd.NoiDung = System.Net.WebUtility.HtmlDecode(collection.Get("ChiTiet"));
        //        //mnddvc.Update(nd);
        //        return RedirectToAction("dichvu");
        //    }
        //    catch
        //    {
        //        return View();
        //    }
        //}



        //public ActionResult Create()
        //{
        //    return View();
        //}

        ////
        //// POST: /TinTuc/Create

        //[HttpPost]
        //public ActionResult Create(FormCollection collection)
        //{
        //    try
        //    {
        //        // TODO: Add insert logic here
        //        dv.MaDV = mdv.GetMax() + 1;
        //        dv.TenDV = collection.Get("TenDV");
        //        dv.NoiDung = collection.Get("ChiTiet");
              
        //        dv.HienThi = true;
                
        //        if (mdv.GetMaxTT() == 0 || mdv.GetTotal_DichVu() == 0)
        //        {
        //            dv.ThuTu = 1;
        //        }
        //        else
        //            dv.ThuTu = mdv.GetMaxTT() + 1;

        //        mdv.Save(dv);
        //        return RedirectToAction("dichvu");
        //    }
        //    catch
        //    {
        //        return View();
        //    }
        //}
        //public ActionResult Edit(int id)
        //{
        //    ViewData["dichvus"] = mdv.GetByID(id);
        //    return View();
        //}

        ////
        //// POST: /TinTuc/Edit/5

        //[HttpPost]
        //public ActionResult Edit(int id, FormCollection collection)
        //{
        //    try
        //    {
        //        // TODO: Add update logic here
        //        dv.MaDV = id;
        //        dv.TenDV = collection.Get("TenDV");
               

        //        dv.NoiDung = System.Net.WebUtility.HtmlDecode(collection.Get("ChiTiet"));
        //        dv.ThuTu = int.Parse(collection.Get("ThuTu"));
        //        mdv.Update(dv);
        //        return RedirectToAction("dichvu");
        //    }
        //    catch
        //    {
        //        return View();
        //    }
        //}

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Delete(int ma)
        {

            string error = mdv.Delete(ma);
            if (!String.IsNullOrEmpty(error))
                return Json(error);
            return Json(String.Empty);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult HienThi(int ma)
        {

            string error = mdv.HienThi(ma);
            if (!String.IsNullOrEmpty(error))
                return Json(error);
            return Json(String.Empty);
        }

    }
}
